package com.wantup.miaosha.utils;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;

/**
 * @author Zhaoluowei
 * @version 1.0
 * @date 2019/6/4 15:04
 */
@Slf4j
public class MD5Util {
    private static final String salt = "1a2b3c4d";

    public static String md5(String src) {
        return DigestUtils.md5Hex(src);
    }

    //加盐加密
    public static String inputPassFormPass(String inputPass) {
        String str = "" + salt.charAt(0) + salt.charAt(2) + inputPass + salt.charAt(5) + salt.charAt(4);
        return DigestUtils.md5Hex(str);
    }

    public static String fromPassToDBPass(String inputPass, String salt) {
        String str = "" + salt.charAt(0) + salt.charAt(2) + inputPass + salt.charAt(5) + salt.charAt(4);
        return DigestUtils.md5Hex(str);
    }

    /**
     * 实际使用方法
     *
     * @return
     */
    public static String inputPassToDBPass(String inputPass, String salt) {
        String passFormPass = inputPassFormPass(inputPass);
        String dbPass = fromPassToDBPass(passFormPass, salt);
        return dbPass;
    }


    public static void main(String[] args) {
//        log.info("" + inputPassFormPass("123456"));
//        log.info("" + fromPassToDBPass(inputPassFormPass("123456"), "1a2b3c4d"));
        log.info(inputPassToDBPass("d018506bc314a32b93eb214102399a63", "12345678"));//d018506bc314a32b93eb214102399a63
    }


}
